<?php namespace app\admin\controller;
class Tag extends Common {
   protected $db;
   public function __init(){
      $this->db=new \system\model\Tag();
   }
    //展示页面
    public function index(){
	   $data = Db::table('tag')->get();
//       p($data);
       View::with('data',$data);
       return view();
    }
    //添加
   public function store(){
	  if(IS_POST)
	  {
		 $res = $this->db->store();
		 if($res['valid']){
			//添加成功
			message($res['message'],u('index'),'success');
		 }
		 message($res['message'],'back','error');

	  }
       return view();
   }
   //编辑
   public function edit(){
	  $tid=q('get.tid');
	  if(IS_POST)
	  {
	     $res=$this->db->edit($tid);
		 if($res){
			message($res['message'],u('admin/tag/index'),'success');
		 }
		 message($res['message'],'back','error');
	  }
	  //获取旧数据
//	  p($tid);
	  $oldData=Db::table('tag')->find($tid);
	  View::with('oldData',$oldData);
      return view();
   }
   //删除
   public function del(){
	  $tid=q('get.tid');
	  $res = \system\model\Tag::delete($tid);
	  if($res){
		 message('标签删除成功',u('index'),'success');
	  }
	  message('标签失败','back','error');
   }
}
